import React, { Component } from 'react';

class Error extends Component {
    state = {
      hasError:false,
      error:null,
      errorinfo:null,
    }
  
   componentDidCatch(error,errorinfo){
     this.setState({
         hasError:true,
         error:error,
         errorinfo:errorinfo
     })
  }

    render() {
        if(this.state.hasError){
            return(
                <div> { this.props.render( this.state.error) } </div>
            )
        }
        else {
            return this.props.children 
        }
    }
}

export default Error;